﻿using System.Windows;
using System.Windows.Controls;

namespace Predica.FimExplorer.UI.WPF.Import
{
    /// <summary>
    /// Interaction logic for ImportedObjectsWindow.xaml
    /// </summary>
    public partial class ImportedObjectsWindow : Window
    {
        ImportedObjectsModel _model;
        ReferenceColumnDetector _referenceColumnDetector;

        public ImportedObjectsWindow()
        {
            InitializeComponent();

            _referenceColumnDetector = new ReferenceColumnDetector();
        }

        public void Initialize(ImportedObjectsModel model)
        {
            _model = model;
            this.DataContext = model;
        }

        private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
        {
            // only references are marked as objects, all other are strings
            _referenceColumnDetector.ProcessAutogeneratedColumn<object>(e
                , id =>
                {
                    _model.DetailsById(id);
                });
        }
    }
}
